package auth

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	v1 "gitee.com/liuxuezhan/ar-platform/rpc-client/authRoleClient/api/role/v1"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetAccountRolesLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 获取账户角色列表
func NewGetAccountRolesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAccountRolesLogic {
	return &GetAccountRolesLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetAccountRolesLogic) GetAccountRoles(req *types.GetAccountRolesRequest) (resp *types.GetAccountRolesResponse, err error) {
	reply, err := l.svcCtx.AuthRoleRpc.GetAccountRoles(l.ctx, &v1.GetAccountRolesRequest{
		AccountId:   req.AccountId,
		AccountType: v1.AccountType(req.AccountType),
		Status:      v1.Status(req.Status),
	})
	if err != nil {
		return resp, err
	}

	resp = &types.GetAccountRolesResponse{}
	for _, role := range reply.List {
		resp.List = append(resp.List, types.AccountRoles{
			RoleId:   role.GetRoleId(),
			RoleName: role.GetRoleName(),
			Status:   int8(role.GetStatus()),
		})
	}

	return resp, err
}
